#version 130

out float SpecularHighlight;

out vec3 LightIntensity;
out vec3 Position;
out vec3 Normal;
out vec4 TexCoord;
out vec3 Normal_cameraspace;
out vec3 EyeDirection_cameraspace;
out vec3 LightDirection_cameraspace;

uniform vec4 LightPosition; // Light position in eye coords.
uniform vec3 EyeVector; // Eye vector;
uniform vec3 Kd; // Diffuse reflectivity
uniform vec3 Ld; // Light source intensity

uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 ProjectionMatrix;

uniform mat4 PV;

void main()
{
	// Convert normal and position to eye coords
	vec3 tnorm = normalize( NormalMatrix * gl_Normal);
	//vec3 tnorm = normalize( NormalMatrix * normalize(gl_Vertex));
	vec4 eyeCoords = ViewMatrix * ModelMatrix * gl_Vertex;
	vec3 s = normalize(vec3(LightPosition - eyeCoords));
	
	// Pasamos las coordenadas de texturas a los FShaders
	TexCoord = gl_MultiTexCoord0;

	// The diffuse shading equation
	LightIntensity = 0.8 * Ld * Kd * max( dot( s, tnorm ), 0.0 ) + 0.1;
	
	vec3 NormalVector = gl_Normal;
	vec4 LightVector4 = gl_Vertex - LightPosition;
	vec3 LightVector = vec3(LightVector4.x, LightVector4.y, LightVector4.z);
	NormalVector = normalize(NormalVector);
	LightVector = normalize(LightVector);
			
	// Convert position to clip coordinates and pass along
	gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * gl_Vertex;
}